dishService.$inject = ['$http'];

function dishService($http) {
    var appContext = require('../../../config/app.context');
    var urlBase = appContext.path + '/api/dishes';
    var _dishService = {};

    var dishTypes = ['所有', '酒水', '套餐', '小吃', '主食'];

    _dishService.getDishListByMerchantId = function(mId) {
        return $http.get(urlBase + '/findByMerchantId/' + mId);
    }

    _dishService.searchDishes = function(mId, searchArgs) {
        if (!searchArgs.type && !searchArgs.keyWord) {
            return $http.get(urlBase + '/findByMerchantId/' + mId);
        }
        if (!searchArgs.keyWord) {
            return $http.get(urlBase + '/findByMerchantIdAndType/' + mId + '/' + dishTypes[searchArgs.type]);
        }
        if (!searchArgs.type) {
            return $http.get(urlBase + '/findByMerchantIdAndName/' + mId + '/' + searchArgs.keyWord);
        }
        return $http.get(urlBase + '/findByAll/' + mId + '/' + dishTypes[searchArgs.type] + '/' + searchArgs.keyWord);
    }

    return _dishService;
}

module.exports = dishService;